import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'id',
    label: '主键',
  },
  {
    component: 'Input',
    fieldName: 'csdnUsername',
    label: 'csdn账号',
  },
  {
    component: 'Input',
    fieldName: 'articleTitle',
    label: '文章标题',
  },
  {
    component: 'Input',
    fieldName: 'articleTag',
    label: '文章标签',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.BWF_CSDN_ARTICLE_SOURCE 便于维护
      options: getDictOptions('bwf_csdn_article_source'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'articleSource',
    label: '文章来源',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.BWF_CSDN_ARTICLE_SCOPE 便于维护
      options: getDictOptions('bwf_csdn_article_scope'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'articleScope',
    label: '文章可见范围',
  },
  {
    component: 'RangePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'releaseTime',
    label: '发布时间',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.BWF_CSDN_RELEASE_STATUS 便于维护
      options: getDictOptions('bwf_csdn_release_status'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'releaseStatus',
    label: '发布状态 ',
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '主键',
    field: 'id',
  },
  {
    title: 'csdn账号',
    field: 'csdnUsername',
  },
  {
    title: '文章标题',
    field: 'articleTitle',
  },
  {
    title: '文章内容',
    field: 'articleContent',
  },
  {
    title: '文章标签',
    field: 'articleTag',
  },
  {
    title: '文章摘要',
    field: 'articleAbstract',
  },
  {
    title: '文章来源',
    field: 'articleSource',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.BWF_CSDN_ARTICLE_SOURCE 便于维护
        return renderDict(row.articleSource, 'bwf_csdn_article_source');
      },
    },
  },
  {
    title: '文章可见范围',
    field: 'articleScope',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.BWF_CSDN_ARTICLE_SCOPE 便于维护
        return renderDict(row.articleScope, 'bwf_csdn_article_scope');
      },
    },
  },
  {
    title: '发布时间',
    field: 'releaseTime',
  },
  {
    title: '发布状态 ',
    field: 'releaseStatus',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.BWF_CSDN_RELEASE_STATUS 便于维护
        return renderDict(row.releaseStatus, 'bwf_csdn_release_status');
      },
    },
  },
  {
    title: '备注',
    field: 'remark',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '主键',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: 'csdn账号',
    fieldName: 'csdnUsername',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '文章标题',
    fieldName: 'articleTitle',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '文章内容',
    fieldName: 'articleContent',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '文章标签',
    fieldName: 'articleTag',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '文章摘要',
    fieldName: 'articleAbstract',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '文章来源',
    fieldName: 'articleSource',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.BWF_CSDN_ARTICLE_SOURCE 便于维护
      options: getDictOptions('bwf_csdn_article_source'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    label: '文章可见范围',
    fieldName: 'articleScope',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.BWF_CSDN_ARTICLE_SCOPE 便于维护
      options: getDictOptions('bwf_csdn_article_scope'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    label: '发布时间',
    fieldName: 'releaseTime',
    component: 'RangePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
  {
    label: '发布状态 ',
    fieldName: 'releaseStatus',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.BWF_CSDN_RELEASE_STATUS 便于维护
      options: getDictOptions('bwf_csdn_release_status'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    rules: 'required',
  },
];
